package demo.activiti.spring;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Sample {

    public static void main(String[] args) {
        // 创建 Spring 应用上下文
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");

        // 获取相关服务
        RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
        TaskService taskService = applicationContext.getBean(TaskService.class);

        // 启动流程
        runtimeService.startProcessInstanceByKey("process1");

        // 查询第一个任务
        Task task1 = taskService.createTaskQuery().singleResult();
        System.out.println(task1.getName());

        // 完成第一个任务
        taskService.complete(task1.getId());

        // 查询第二个任务
        Task task2 = taskService.createTaskQuery().singleResult();
        System.out.println(task2.getName());

        // 完成第二个任务
        taskService.complete(task2.getId());
    }
}
